//
//  JGApplyWithdrawalsController.m
//  JGRider
//
//  Created by 单启志 on 2018/2/5.
//  Copyright © 2018年 ffq. All rights reserved.
//

#import "JGApplyWithdrawalsController.h"
#import "JGApplyWithdrawalsContentView.h"
#import "JGSubmitSuccessAlertView.h"
#import "WJYAlertView.h"
#import "JGApplyWithDrawalsApi.h"
@interface JGApplyWithdrawalsController ()<JGApplyWithdrawalsContentViewDelegate,JGSubmitSuccessAlertViewDelegate>
@property(nonatomic,strong)JGApplyWithdrawalsContentView *contView;
@property(nonatomic,strong)WJYAlertView *alertView;
@property(nonatomic,strong)JGApplyWithDrawalsApi *api;
@end

@implementation JGApplyWithdrawalsController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self layoutSubViews];
}

-(void)layoutSubViews{

    self.title=@"申请提现";
    [self.view addSubview:self.contView];
}

#pragma mark - content view delegate
//提交
-(void)contentViewEventWithMoney:(CGFloat)money{
    NSString *moneyStr=[NSString stringWithFormat:@"%.2f",money];
  MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
    FQWeakSelf(self);
    [self.api ApplyWithDrawalsWithMoney:moneyStr successBlock:^(id result) {
        [hud hideAnimated:YES];
        if ([result[@"data"][@"state"]isEqualToString:@"15005"]) {

            //成功
            [weakself.alertView show];
        }else{
            [MBProgressHUD showError:result[@"data"][@"msg"] ToView:self.view];
        }

    } faileBlock:^(id error) {
         [hud hideAnimated:YES];
        [MBProgressHUD showError:@"失败" ToView:self.view];
    }];

    //[self.alertView show];


}

#pragma mark -submitSuccess view delegate
-(void)submitSuccessAlertViewEvent{
    [self.alertView dismissWithCompletion:^{
        JGpopViewController;
    }];
}

#pragma mark - override
-(WJYAlertView *)alertView{
    if (!_alertView) {
        JGSubmitSuccessAlertView *alertCustomV=[[JGSubmitSuccessAlertView alloc]initWithFrame:CGRectMake(0, 0, AdaptedWidth(258), AdaptedWidth(142))];
        alertCustomV.delegate=self;
        _alertView=[[WJYAlertView alloc]initWithCustomView:alertCustomV dismissWhenTouchedBackground:NO];
    }
    return _alertView;
}

-(JGApplyWithdrawalsContentView *)contView{
    if (!_contView) {
        _contView=[[JGApplyWithdrawalsContentView alloc]initWithFrame:CGRectMake(0, self.lmj_navgationBar.height, JGScreenW, JGScreenH-self.lmj_navgationBar.height)];
        _contView.delegate=self;
    }
    return _contView;

}

-(JGApplyWithDrawalsApi *)api{
    if (!_api) {
        _api=[[JGApplyWithDrawalsApi alloc]init];
    }
    return _api;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

-(void)viewWillDisappear:(BOOL)animated{

    [self.api.chainReq stop];
    [super viewWillDisappear:animated];

}

@end
